/*
 * @Author: ZhanXie
 * @Date: 2020-09-16 22:29:45
 * @LastEditors: ZhanXie
 * @LastEditTime: 2020-09-17 13:00:39
 * @Description: 微博 @ 关系 controller
 * @FilePath: /weibo/src/routes/api/blog-at.js
 */
const router = require('koa-router')()
const { loginCheck } = require('../../middlewares/loginChecks')
const { getAtMeBlogList } = require('../../controller/blog-at')
const { getBlogListStr } = require('../../utils/blog')

router.prefix('/api/atMe')

// 加载更多
router.get('/loadMore/:pageIndex', loginCheck, async (ctx, next) => {
  let { pageIndex } = ctx.params
  pageIndex = parseInt(pageIndex) // 转换 number 类型
  const { id: userId } = ctx.session.userInfo
  const result = await getAtMeBlogList(userId, pageIndex)

  // 渲染模板
  result.data.blogListTpl = getBlogListStr(result.data.blogList)
  ctx.body = result
})

module.exports = router